//
//  CMDBResultPeopleCell.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/28.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBResultPeopleCell: CustomBaseCell {

    var iconImageView : UIImageView = UIImageView.getInstance()
    
    var nameLabel : UILabel         = UILabel.getInstance()
    
    var tagsView : UIView           = UIView.getInstance()
    
    var movieView : UIView          = UIView.getInstance()
    
    override func setupCell() {
        super.setupCell()
        
        backgroundColor = UIColor.whiteColor()
    }
    
    override func cellBuildSubViews() {
        super.cellBuildSubViews()
        
        iconImageView.frame               = CGRect(x: KleftMargin, y: KleftMargin, width: 40, height: 40)
        
        iconImageView.image = UIImage(named: "test头像")
        
        iconImageView.layer.cornerRadius  = 5
        
        iconImageView.layer.masksToBounds = true
        
        contentView.addSubview(iconImageView)
        
        nameLabel.frame                   = CGRect(x: CGRectGetMaxX(self.iconImageView.frame) + KleftMargin, y: KleftMargin, width: 100, height: 16)
        nameLabel.font                    = CMDB_16_Bold_FONT
        
        contentView.addSubview(nameLabel)
        
        nameLabel.text = "冯小磊"
        
        buildTags()
        
        buildMovies()
    }
    
    func buildTags(){
        
        tagsView.frame = CGRect(x: CGRectGetMinX(nameLabel.frame), y: CGRectGetMaxY(nameLabel.frame) + 5, width: 200, height: 20)
        
        for i in 0 ..< 3 {

            let attributteLabel = UIButton(title: "演员", borderColor: word38Color, titleSizeFont: CMDB_11_FONT, isShowBorder: true)
            
             attributteLabel.frame = CGRect(x: (30 + 4) * i, y: 2, width: 30, height: 15)
            
            tagsView.addSubview(attributteLabel)
            
        }
        
        contentView.addSubview(tagsView)
    
    }
    
    func buildMovies(){
        
        movieView.frame = CGRect(x: CGRectGetMinX(nameLabel.frame), y: CGRectGetMaxY(tagsView.frame) , width: 200, height: 20)
        
        for i in 0 ..< 3 {
            
            let attributteLabel = UIButton(title: "狼图腾", borderColor: word38Color, titleSizeFont: CMDB_13_FONT, isShowBorder: false)
            
            attributteLabel.contentHorizontalAlignment = .Left
            
            attributteLabel.frame = CGRect(x: (50 + 5) * i, y: 0, width: 50, height: 20)
            
            movieView.addSubview(attributteLabel)
            
        }
        contentView.addSubview(movieView)
    }
    
    override func loadContent() {
        
    }
    
    override func setHighlighted(highlighted: Bool, animated: Bool) {
        
        if highlighted {
            
            UIView.animateWithDuration(0.35, delay: 0, options: .BeginFromCurrentState, animations: {
                //            self.iconImageView.alpha = (highlighted == true ? 0.5    : 1.0)
                self.nameLabel.x  = (highlighted == true ? CGRectGetMaxX(self.iconImageView.frame) + KleftMargin + 4 : CGRectGetMaxX(self.iconImageView.frame) + KleftMargin)
                
                self.backgroundColor  = (highlighted == true ? UIColor.randomColor().colorWithAlphaComponent(0.1) : UIColor.whiteColor())
                }, completion: { (finished) in
            })
            
           
        }else{
            
            UIView.animateWithDuration(0.5, delay: 0, options: .BeginFromCurrentState, animations: {
                //            self.iconImageView.alpha = (highlighted == true ? 0.5    : 1.0)
                self.nameLabel.x  = (highlighted == true ? CGRectGetMaxX(self.iconImageView.frame) + KleftMargin + 4 : CGRectGetMaxX(self.iconImageView.frame) + KleftMargin)
                self.backgroundColor  = (highlighted == true ? UIColor.randomColor().colorWithAlphaComponent(0.1) : UIColor.whiteColor())
                }, completion: { (finished) in
            })

            let scaleAnimation = POPSpringAnimation(propertyNamed:kPOPViewScaleXY)
            scaleAnimation.toValue = NSValue(CGPoint:CGPointMake(1, 1))
            scaleAnimation.velocity = NSValue(CGPoint:CGPointMake(2, 2))
            scaleAnimation.springBounciness = 20.0
            
            nameLabel.pop_addAnimation(scaleAnimation, forKey: "scaleAnimation")
            
        }
        
    }
}
